define(function (require, exports, module) {
    var angular = require('angular');
    require("pagination");
    require("angular-ui");
    var config = require('/public/js/myservice/config');
    require('/public/js/myservice/contract/contract-common');
    var util = require("util");
    var api_prefix = G_CONFIG["api_prefix"]; //api前缀

    angular.module('ContractCaibao', ['ngUI', 'myNav', 'ContractCommonService'])
        .controller('contractListCaibaoCtrl', ['$scope', 'contractCommonService', function ($scope, contractCommonService) {

            //合同列表
            $scope.contracts = [];

            //查询条件
            $scope.getQueryParams = function (page) {
                var parms = {pageIndex: page || 1};
                parms.pageSize = config.pager().pageSize;

                return parms;
            };
            //查询
            $scope.query = {
                execute: function (page) {
                    var parms = $scope.getQueryParams(page);
                    var get_data = parms;
                    get_data.beginInputDate = this.beginInputDate;
                    get_data.endInputDate = this.endInputDate;
                    var url = api_prefix + "/contract/get-contract-caibao-list";

                    util.myAjax({
                        url: url,
                        type: "GET",
                        context: this,
                        data: get_data,
                        success: function (json) {
                            if (json.retCode === "0") {
                                $scope.contracts = json.data.items;
                                $scope.$applyAsync();

                                $scope.startPageIndex = (parms.pageIndex - 1) * 10;
                                $('#pagination').pagination(parseInt(json.data.total), {
                                    current_page: parms.pageIndex - 1,
                                    num_edge_entries: 1, //边缘页数
                                    num_display_entries: 4, //主体页数
                                    callback: function (page_index, jq) {
                                        $scope.startPageIndex = (page_index - 1) * 10;
                                        $scope.query.execute(page_index);
                                    },
                                    items_per_page: config.pager().pageSize //每页显示1项
                                });

                            } else {
                                this.showTip("获取合同列表失败：" + json.errMsg);
                            }
                        }
                    });
                }
            };

            /**
             * 导出
             */
            $scope.export = function (contract_id) {
                if(contract_id != false){
                    util.confirm('确定要导出充值数据吗？', {
                        ok: function () {
                            var parms = {contract_id: contract_id};
                            var url = api_prefix + '/contract/export-contract-caibao-mx';
                            util.download(url, parms);
                        }
                    });
                    return;
                }
                util.confirm('确定要导出数据吗？', {
                    ok: function () {
                        var parms = {beginInputDate: $scope.query.beginInputDate};
                        parms.endInputDate = $scope.query.endInputDate;
                        var url = api_prefix + '/contract/export-contract-caibao';
                        util.download(url, parms);
                    }
                });
            };

            $scope.query.execute();
        }]);
});